package com.yupi.yupicturebackend.api.baidu.imageRecognition.sub;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

@Deprecated
public class BaiduDemoLandmarkSimple {
    public static String recognizeLandmark(String imageUrl, String cookie, String demoAuth, String demoId) {
        String apiUrl = "https://ai.baidu.com/platform/demo/red/rest/2.0/image-classify/v1/landmark";

        // 构造表单参数（需与浏览器一致）
        String formData = "image_url=" + imageUrl;

        HttpResponse response = HttpRequest.post(apiUrl)
                .header("Content-Type", "application/x-www-form-urlencoded")
                .header("Cookie", cookie)
                .header("Demo-Authentication", demoAuth)
                .header("Demo-Id", demoId)
                .body(formData)
                .execute();

        JSONObject result = JSONUtil.parseObj(response.body());
        if (result.getInt("errorCode") == 0) {
            return result.getByPath("result.result.landmark", String.class);
        } else {
            throw new RuntimeException("API 调用失败: " + result.getStr("errorMsg"));
        }
    }

    public static void main(String[] args) {
        String imageUrl = "https://ai-public-console.cdn.bcebos.com/portal-pc-static/1742892956837/images/technology/imagerecognition/landmark/1.jpg";
        String cookie = "__bid_n=18e13b259fb6128d6aeccb; jsdk-uuid=0d2317c7-54af-4442-9da0-efeaad3af335; BAIDU_WISE_UID=wapp_1714811841000_169; BIDUPSID=E93013524C0C06DCB0F3C23B2664F5B0; PSTM=1729419510; BAIDUID=711BAE685B1E482497C4CF1474DC1620:FG=1; BAIDUID_BFESS=711BAE685B1E482497C4CF1474DC1620:FG=1; ariaDefaultTheme=default; ariaFixed=true; ariaReadtype=1; ariaoldFixedStatus=false; ariaStatus=false; ZFY=N:AWx3tp2:BcQIXHyx0vRlGVtr4kQrN13b9qa5:BFu2I5s:C; H_WISE_SIDS=62037_62325_62347_62246_62421_62422; BDRCVFR[BIVAaPonX6T]=-_EV5wtlMr0mh-8uz4WUvY; H_PS_PSSID=61027_62241_62325_62336_62370_62484_62674_62705_62328_62803_62789; BA_HECTOR=a50h2l0k8g048h8hah258h2haqm31k1jup4nn23; CAMPAIGN_TRACK=; ucbearer-clientid=; bce-login-userid=; SIGNIN_UC=; __cas__id__285=; bce-device-cuid=; __cas__rn__=; ucbearer-token=; bce-verify-status=; CAMPAIGN_TRACK_TIME=; __cas__st__285=; ucbearer-ucid=; ucbearer-devicecode=; ppfuid=FOCoIC3q5fKa8fgJnwzbE3sZaS3poGTofPItBD67MTHOloTQtOTfZukshuG+jikLNAEDpjnvum7pdSHAIJ1jzpTWGxetfiFq8MidY6nl7UedrhSK90obzC1JWOoJAfwUjPtMxdHKURbmF00VhoGO4K4UxhUiw4YINwIab+ECsupI6ChqnosgjWh2Hncpw9QYBivEHje70dDI9cAo2PWfIoMJPH5MovrDwZ3FxFzO3MDgLIoZfDeoQINDc6557JgIAqk9tnSno7DG1sHSp/1zqOKz6MkT3uduDoTT+1eHDzwK/94JnJlri2wYCoAaXkNnHUcx/0VZqZfSHNPBK+r5nDIXTq7Okc7RuAEqwLkBgWjZMX9jYOdyzRhFNLaflFO83YfR6VWPiyiGuIaAQZTWOHz2aZNcaevZYtuiNeT7+wa6pf6/OgtMZXRn49gvdiEm2dM1L+ksxZx66zR7vnv9QwMaoBJg7zP0Wjjc75JNQkAZicwLx3tTw8w2MT/zIqkryfHvVaS5DYvrIJqU4/bCxd2I54J3wSzzaKbktlyvBMPpgmswaScc6DNWb34jFj0X3tdRE0uuHuqiYa5BClFS2V0TCorKi4CobgR419xWaX8IKLJiaNNLOShWdZdlQO2DXXVxcinzKHqUvWTYx45jsiUVlY78AHQGol6CJLQQ8Q797MShlazvdSwPXgJP5z0uMJp9L+3x/Y2GGhW5sit55kwqfnfIy0c7y6uGqwOC6mwJ13AUairLDWhe5SwH+f9kx+4rjNadQYRXY62cs4wa6vu3FNhnx0vECH7/RD7jOBKizxAthRKsNAWrJkv9HC0SPiv+7Ihnh2F6NYKqJz05/zospRHp39A6dkg7O2dgIrVsBAiZVqRumDq+zV3cirOdalgjfdDmOpvo6TsQUOMAzi+EN/orN5/U89vtltzoaJ5TkDJs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WRiNTY0MTM4NzMxNTE2ZDljMTg2YzllN2JjY2E3ZDc3N2YwMWQ2NWFiMGQ4OTI5NGU3M2NlYmNiNmY=; RT=\"z=1&dm=baidu.com&si=6250d975-3670-429c-8a41-a95a6a98ee6c&ss=m8z9wriu&sl=2&tt=5dg&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=5pv&hd=82p\"; bceAccountName=PASSPORT:2779171734; bce-ctl-client-cookies=\"BDUSS,bce-passport-stoken,bce-device-cuid,bce-device-token,BAIDUID\"; bce-passport-stoken=d3a9125fb75915a8f40375d1de76514aedac85682bcd131cc2e64eff78cf93d8; bce-user-info=2025-04-02T09:53:51Z|a192a56e4f3c5929a56f13c4371c3a96; bce-ctl-sessionmfa-cookie=bce-session; bce-session=34448b832e2d4084a58922c8e696df66b33b83390e274a4c9f0526da4b14f5d1|343ef9d2535f32b089b0e6260160d741; bce-login-display-name=*******5225; bce-userbind-source=PASSPORT; bce-auth-type=PASSPORT; bce-login-type=PASSPORT; bce-login-expire-time=\"2025-04-02T02:23:51Z|9a07ca905299ecdadc23635c22385905\"; loginUserId=2779171734; bce-device-token=";
        String demoAuth = "";
        String demoId = "4daae676-abf5-4993-8077-1b7bff974fa";
        System.out.println("识别结果: " + recognizeLandmark(imageUrl, cookie, demoAuth, demoId));
    }
}